#ifndef BOOKMARKSMANAGER_H
#define BOOKMARKSMANAGER_H

#include <QObject>
#include <QUndoStack>
#include <QStringList>

class AutoSaver;
class BookmarkNode;
class BookmarksModel;

class BookmarksManager : public QObject
{
    Q_OBJECT
public:
    explicit BookmarksManager(QObject *parent = 0);
    ~BookmarksManager();

    void addBookmark(BookmarkNode *parent, BookmarkNode *node, int row = -1);
    void removeBookmark(BookmarkNode *node);
    void setTitle(BookmarkNode *node, const QString &newTitle);
    void setUrl(BookmarkNode *node, const QString &newUrl);
    void setTags(BookmarkNode *node, const QString &newTags);
    void changeExpanded();
    BookmarkNode *bookmarks();
    BookmarkNode *menu();
    BookmarkNode *toolbar();
    BookmarkNode *find_folder(BookmarkNode *start_node, const QString& title);
    QStringList find_tag_urls(BookmarkNode *start_node, const QString& tag);

    BookmarksModel *bookmarksModel();
    QUndoStack *undoRedoStack() { return &m_commands; }
    
signals:
    void entryAdded(BookmarkNode *item);
    void entryRemoved(BookmarkNode *parent, int row, BookmarkNode *item);
    void entryChanged(BookmarkNode *item);
    
public slots:
    void importBookmarks();
    void importFromIE();
    void importFromMozilla();
    void importFromHTML();
    void exportBookmarks();

private slots:
    void save() const;

private:
    void load();

    bool m_loaded;
    AutoSaver *m_saveTimer;
    BookmarkNode *m_bookmarkRootNode;
    BookmarksModel *m_bookmarkModel;
    QUndoStack m_commands;

    friend class RemoveBookmarksCommand;
    friend class ChangeBookmarkCommand;
};

#endif // BOOKMARKSMANAGER_H
